<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>slicearray</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="sleighbells.html" title="sleighbells" />
    <link rel="next" href="slider16.html" title="slider16" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">slicearray</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="sleighbells.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="slider16.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="slicearray"></a>
      <div class="titlepage"></div>
      <a id="IndexSlicearray" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">slicearray</span>
        </h2>
        <p>slicearray — 
      Take a slice of a vector.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp147594272"></a>
        <h2>Description</h2>
        <p>
      Take a slice of a vector (one-dimensional k-rate array).
    </p>
      </div>
      <div class="refsect1">
        <a id="idp147635520"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">karray <span class="command"><strong>slicearray</strong></span> kinarray, istart, iend</pre>
      </div>
      <div class="refsect1">
        <a id="idp147637664"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>istart</em></span> -- index of the first part of the answer.
    </p>
        <p>
      <span class="emphasis"><em>iend</em></span> -- index of the first element of the answer.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp147640192"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the slicearray opcode. It uses the file <a class="ulink" href="examples/slicearray.csd" target="_top"><em class="citetitle">slicearray.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp147642048"></a>
          <p class="title">
            <strong>Example 824. Example of the slicearray opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-n
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

<span class="oblock">instr</span> 1

<span class="comment">;create and fill an array</span>
kArr[]  <span class="opc">genarray_i</span> 1, 9

<span class="comment">;print the content</span>
        <span class="opc">printf</span>  "<span class="op">%</span>s", 1, "kArr <span class="op">=</span> whole array\n"
kndx    <span class="op">=</span>       0
  until kndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr) do
        <span class="opc">printf</span>  "kArr[<span class="op">%</span>d] <span class="op">=</span> <span class="op">%</span>f\n", kndx<span class="op">+</span>1, kndx, kArr[kndx]
kndx    <span class="op">+</span><span class="op">=</span>      1
  od

<span class="comment">;build new arrays for the slices</span>
kArr1[] <span class="opc">init</span>    5
kArr2[] <span class="opc">init</span>    4

<span class="comment">;put in first five and last four elements</span>
kArr1   <span class="opc">slicearray</span> kArr, 0, 4
kArr2   <span class="opc">slicearray</span> kArr, 5, 8

<span class="comment">;print the content</span>
        <span class="opc">printf</span>  "<span class="op">%</span>s", 1, "\nkArr1 <span class="op">=</span> slice from index 0 to index 4\n"
kndx    <span class="op">=</span>       0
  until kndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr1) do
        <span class="opc">printf</span>  "kArr1[<span class="op">%</span>d] <span class="op">=</span> <span class="op">%</span>f\n", kndx<span class="op">+</span>1, kndx, kArr1[kndx]
kndx    <span class="op">+</span><span class="op">=</span>      1
  od
        <span class="opc">printf</span>  "<span class="op">%</span>s", 1, "\nkArr2 <span class="op">=</span> slice from index 5 to index 8\n"
kndx    <span class="op">=</span>       0
  until kndx <span class="op">==</span> <span class="opc">lenarray</span>(kArr2) do
        <span class="opc">printf</span>  "kArr2[<span class="op">%</span>d] <span class="op">=</span> <span class="op">%</span>f\n", kndx<span class="op">+</span>1, kndx, kArr2[kndx]
kndx    <span class="op">+</span><span class="op">=</span>      1
  od

        <span class="opc">turnoff</span>
<span class="oblock">endin</span>


<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span> 1 0 1
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp147646336"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="vectorial.html" title="Vectorial Opcodes"><em class="citetitle"></em>Vectorial opcodes</a>
</p>
      </div>
      <div class="refsect1">
        <a id="idp147648384"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: John ffitch</td>
          </tr>
          <tr>
            <td>Codemist Ltd</td>
          </tr>
          <tr>
            <td>2013</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in version 6.00</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="sleighbells.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="slider16.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">sleighbells </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> slider16</td>
        </tr>
      </table>
    </div>
  </body>
</html>
